﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Component;

public partial class BackEnd_CategoryModify : System.Web.UI.UserControl
{
        public string _Url = "";
        public string _idCat = "";
        CategoryInfo info;
        NewsInfo ninfo;
        public string _parent = "";
        public string _Session = "";
        string _UrlCateSub = BackEndQuery._AdminQuery + BackEndQuery._CategorySub + "&" + ConstString._Parent + ConstString._dauBang;
        string _UrlNewsL = BackEndQuery._AdminQuery + BackEndQuery._NewsL + "&" + ConstString._Parent + ConstString._dauBang;
        string _UrlCateL = BackEndQuery._AdminQuery + BackEndQuery._CategoryL;
        protected void Page_Load(object sender, EventArgs e)
        {
            _idCat = Request.QueryString[ConstString._idcat] ?? "";
            _parent = Request.QueryString[ConstString._Parent] ?? "";
            //txtContent.Visible = false;
            if (_parent == "0")
                _Url = "<a href=\"" + BackEndQuery._AdminQuery + BackEndQuery._CategoryL + "\"> Danh sách danh mục" + "</a>";
            else
            {
                _Url = _Session = ConvertType.ToString(Session[BackEndQuery._CategorySub]).ToString();
            }
            
        }        
        protected void cmdLuu_Click(object sender, EventArgs e)
        {
            info = new CategoryInfo();
            ninfo = new NewsInfo();
            if (rdBtn.Items[1].Selected == true)
            {
                ninfo.Content = ConvertType.ToString(txtContent.Value.Trim());
                ninfo.Titile = txtName.Text;
                ninfo.Summary = txtSummary.Text;
                ninfo.Parent = _parent == "" ? 0 : int.Parse(_parent);
                if (NewsDB.Insert(ninfo))
                {
                    lbMessage.Text = ConstString._themTC;
                }
                else
                    lbMessage.Text = ConstString._themTB;
                Response.Redirect(_UrlNewsL + ConvertType.ToString(ninfo.Parent));
            }
            else
            {
                info.Summary = txtSummary.Text;
                info.Name = ConvertType.ToString(txtName.Text);
                info.Parent = _parent == "" ? 0 : int.Parse(_parent);
                if (CategoryDB.Insert(info))
                {
                    lbMessage.Text = ConstString._themTC;
                }
                else
                    lbMessage.Text = ConstString._themTB;

                Response.Redirect(_Url);
            }
        }

        //protected void hientxtContent_Click(object sender, EventArgs e)
        //{
        //    txtContent.Visible = true;
        //    rdBtn.Items[1].Selected=true;
        //}
        protected void rdBtn_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rdBtn.Items[1].Selected = true)
                txtContent.Visible = true;
            
        }
        protected void txtSummary_TextChanged(object sender, EventArgs e)
        {

        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            txtContent.Visible = true;
            rdBtn.Items[1].Selected = true;
        }
}
